This repository was archived by the owner on Sep 17, 2025. It is now read-only.
Fix set trace attributes for django when host is not allowed#1026
Open
sirkonst wants to merge 1 commit intocensus-instrumentation:masterfrom
Open
Fix set trace attributes for django when host is not allowed#1026sirkonst wants to merge 1 commit intocensus-instrumentation:masterfrom
sirkonst wants to merge 1 commit intocensus-instrumentation:masterfrom
Conversation
`request.get_host()` raises DisallowedHost exception if request came with HOST witch not configured
in ALLOWED_HOSTS setting.
Django provides special methods `request._get_raw_host()` and `request.get_raw_uri()` to get values
like `get_host()` and `build_absolute_uri()` but without checking by ALLOWED_HOSTS.
Without fix error will be like:
```
ERROR opencensus.ext.django.middleware:middleware.py:235 Failed to trace request
Traceback (most recent call last):
File "/home/konst/develop/opencensus-python/contrib/opencensus-ext-django/opencensus/ext/django/middleware.py", line 211, in process_request
attribute_value=request.get_host())
File "/home/konst/develop/opencensus-python/.nox/unit-2-7/lib/python2.7/site-packages/django/http/request.py", line 113, in get_host
raise DisallowedHost(msg)
DisallowedHost: Invalid HTTP_HOST header: 'notallowedhost'. You may need to add u'notallowedhost' to ALLOWED_HOSTS.
```
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
request.get_host()raises DisallowedHost exception if request came with HOST witch not configuredin ALLOWED_HOSTS setting.
Django provides special methods
request._get_raw_host()andrequest.get_raw_uri()to get valueslike
get_host()andbuild_absolute_uri()but without checking by ALLOWED_HOSTS.Without fix error will be like: